﻿using CarArranger.Model;
using System;
using System.Windows.Forms;

namespace CarArranger.Forms
{
    public partial class LayoutSettingForm : Form
    {
        public Yard Yard { get; set; }

        public LayoutSettingForm()
        {
            InitializeComponent();
            Yard = new Yard();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            AddStationTrack form = new AddStationTrack();
            DialogResult result = form.ShowDialog();
            if(result == DialogResult.OK)
            {
                string[] s = form.TrackString.Split(',');
                foreach(string ss in s)
                {
                    Yard.Tracks.Add(new Track(ss));
                }
                UpdateList();
            }
        }

        private void UpdateList()
        {
            listView1.Items.Clear();
            foreach (Track track in Yard.Tracks)
            {
                ListViewItem listViewItem = new ListViewItem();
                listViewItem.Text = track.Name;
                listViewItem.Tag = track;
                this.listView1.Items.Add(listViewItem);
            }
        }

        private void button7_Click(object sender, EventArgs e)
        {
            if(radioButton1.Checked)
            {
                Yard.IsLeftHandWork = true;
            }
            else
            {
                Yard.IsLeftHandWork = false;
            }
            this.DialogResult = DialogResult.OK;
            this.Close();
        }

        private void button8_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }
    }
}
